const Log = require('../model/log')
const Sequelize = require('sequelize')
const Op = Sequelize.Op

// 分页查询log
var getLogList = function (params) {
  let offset = (params.current - 1) * params.size || 0
  let limit = params.size || 10
  let screenKeywords = params.screenKeywords || ''
  let filterKeywords = params.filterKeywords || ''
  let type = params.type || 0
  if (type === 0 && !filterKeywords) {
    return Log.findAndCountAll({
      where: {
        content: {
          [Op.like]:'%' + screenKeywords + '%'
        }
      },
      offset,
      limit: limit
    })
  } else if (type === 0 && filterKeywords) {
    return Log.findAndCountAll({
      where: {
        content: {
          [Op.like]:'%' + screenKeywords + '%',
          [Op.notLike]:'%' + filterKeywords + '%',
        }
      },
      offset,
      limit: limit
    })
  } else if (type !== 0 && !filterKeywords) {
    return Log.findAndCountAll({
      where: {
        type: type,
        content: {
          [Op.like]:'%' + screenKeywords + '%'
        }
      },
      offset,
      limit: limit
    })
  } else {
    return Log.findAndCountAll({
      where: {
        type: type,
        content: {
          [Op.like]:'%' + screenKeywords + '%',
          [Op.notLike]:'%' + filterKeywords + '%',
        }
      },
      offset,
      limit: limit
    })
  }
}

var logService = {
  getLogList
}
module.exports = logService


